
import { getCookie } from '../utils/index'
import { robotsapi } from './request'



export const getUserList = async () => {
    let response = await robotsapi.get(`/users`)
    return response.data
}



export const addUser = async (username, password) => {
    let response = await robotsapi.post(`/user`, {
        name: username,
        password,
    }, {
        // Missing CSRF token
        // https://github.com/IndominusByte/fastapi-jwt-auth/issues/25
        // https://github.com/axios/axios/issues/2024
        headers: {
            'X-CSRF-TOKEN': getCookie('csrf_access_token')
        }
    })

    return response.data
    // console.log(`login response=`, response)
}


export const removeUser = async (id) => {
    let response = await robotsapi.delete(`/user`, {
        data: { // 请求参数放在请求体
            id
        },
        headers: {
            'X-CSRF-TOKEN': getCookie('csrf_access_token')
        }
    })

    return response.data
}
